<link rel='stylesheet' type='text/css' href='<?php echo $this->baseUrl() ?>/public/css/input.css'/>
<link rel='stylesheet' type='text/css' href='<?php echo $this->baseUrl() ?>/public/css/jquery-ui/jquery-ui-1.10.3.css'/>
<div id="input-content">
    <?php
    if (!empty($this->session->user) &&
            ($this->session->user->role == Core_Role::ROLE_INPUT ||
            $this->session->user->role == Core_Role::ROLE_ADMIN)):
        ?>
        <div class='wrap-export'>
            <a href="<?php echo $this->baseUrl() ?>/service/export-pdf/giid/<?php echo $this->gi->id ?>" 
               target='_blank' <?php echo empty($this->gi->ats) ? "onclick='return false'" : "" ?> >
                <span class='button' <?php echo empty($this->gi->ats) ? "style='color: #CCC'" : "" ?>>Export Trip Account</span>
            </a>        
            <a href="<?php echo $this->baseUrl() ?>/service/profoma/giid/<?php echo $this->gi->id ?>" target='_blank'>
                <span class='button'>Export Profoma</span>
            </a>
            <a href="<?php echo $this->baseUrl() ?>/service/excel-trip-account/giid/<?php echo $this->gi->id ?>" target='_blank'>
                <span class='button'>Export Excel</span>
            </a>
        </div>
    <?php endif; ?>
    <div class="input-step" id="wrap-general-info">
        <div class="step-content">
            <h1 class="first"> General information</h1>
            <div class="cleft gi_left">
                <div class="item">
                    <label for='refno'>Ref No.:</label>
                    <div class="reselect">
                        <?php echo $this->gi->ref_no ?>
                    </div>
                </div>
                <div class="item">
                    <label for="customer_name">Principal name:</label>
                    <div class="reselect">
                        <?php echo $this->customer_name ?>
                    </div>
                </div>
                <div class="item">
                    <label for="customer_name">Attn:</label>
                    <div class="reselect">
                        <?php if ($this->gi->attn): ?>
                            <?php echo $this->gi->attn ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="vessel">Vessel name:</label>
                    <div class="reselect">
                        <?php echo $this->gi->vessel ?>
                    </div>
                </div>
                <div class="item">
                    <label for='purpose_of_call'>Purpose of Call:</label>
                    <div class="reselect">
                        <?php echo $this->gi->purpose_of_call ?>
                    </div>
                </div>
                <div class="item">
                    <label for="gtr">GRT:</label>
                    <div class="reselect">
                        <?php echo number_format($this->gi->gtr, 0, '.', ',') ?>
                    </div>
                </div>
                <div class="item">
                    <label for='port_of_call'>Port of Call:</label>
                    <div class="reselect">
                        <?php if ($this->gi->port_of_call > 0): ?>
                            <?php echo $this->port_of_call_name ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for='buoy'>Buoy/Berth:</label>
                    <div class="reselect">
                        <?php if ($this->gi->buoy > 0): ?>
                            <?php echo $this->buoy_name ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for='last_port_of_call'>Last Port of Call:</label>
                    <div class="reselect">
                        <?php if ($this->gi->last_port_of_call != '-1'): ?>
                            <?php echo $this->gi->last_port_of_call ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for='next_port_of_call'>Next Port of Call:</label>
                    <div class="reselect">
                        <?php if ($this->gi->next_port_of_call != '-1'): ?>
                            <?php echo $this->gi->next_port_of_call ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for='commodities'>Commodities:</label>
                    <div class="reselect">
                        <?php echo $this->gi->commodities ?>
                    </div>
                </div>
                <div class="item">
                    <label for='quantity'>Quantity:</label>
                    <div class="reselect">
                        <?php if ($this->gi->quantity): ?>
                            <?php if ((int) $this->gi->quantity != $this->gi->quantity): ?>
                                <?php echo number_format($this->gi->quantity, 2, '.', ',') ?>
                            <?php else: ?>
                                <?php echo number_format($this->gi->quantity, 0, '.', ',') ?>
                            <?php endif; ?>
                            <?php echo $this->gi->quantity_unit ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <div class="cright gi_right">
                <div class="item">
                    <label for="voyage_no">Voyage No.:</label>
                    <div class="reselect">
                        <?php if ($this->gi->voyage_no): ?>
                            <?php echo $this->gi->voyage_no ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="flag">Flag:</label>
                    <div class="reselect">
                        <?php echo $this->gi->flag ?>
                    </div>
                </div>
                <div class="item">
                    <label for="eta">ETA:</label>
                    <div class="reselect">
                        <?php if ($this->gi->eta): ?>
                            <?php echo date(DATE_FORMAT, $this->gi->eta) ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="ata">ATA:</label>
                    <div class="reselect">
                        <?php if ($this->gi->ata): ?>
                            <?php echo date(DATE_FORMAT, $this->gi->ata) ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="etb">ETB:</label>
                    <div class="reselect">
                        <?php if ($this->gi->etb): ?>
                            <?php echo date(DATE_FORMAT, $this->gi->etb) ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="atb">ATB:</label>
                    <div class="reselect">
                        <?php if ($this->gi->atb): ?>
                            <?php echo date(DATE_FORMAT, $this->gi->atb) ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="ets">ETS:</label>
                    <div class="reselect">
                        <?php if ($this->gi->ets): ?>
                            <?php echo date(DATE_FORMAT, $this->gi->ets) ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="ats">ATS:</label>
                    <div class="reselect">
                        <?php if ($this->gi->ats): ?>
                            <?php echo date(DATE_FORMAT, intval($this->gi->ats)) ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="vessel_on_arrival">Vessel on Arrival:</label>
                    <div class="reselect">
                        <?php if ($this->gi->vessel_on_arrival): ?>
                            <div style="width: 60%">
                                <a class="fancybox" data-fancybox-group="gallery1" href="<?php echo UPLOAD_URL . $this->gi->vessel_on_arrival ?>">
                                    <img alt="No image" height="50px" width="100px" style='padding:10px 0px;' src="<?php echo UPLOAD_URL . $this->gi->vessel_on_arrival ?>"/>
                                </a>
                            </div>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="vessel_on_departure">Vessel on Departure:</label>
                    <div class="reselect">
                        <?php if ($this->gi->vessel_on_departure): ?>
                            <div style="width: 60%">
                                <a class="fancybox" data-fancybox-group="gallery1" href="<?php echo UPLOAD_URL . $this->gi->vessel_on_departure ?>">
                                    <img alt="No image" height="50px" width="100px" style='padding:10px 0px;' src="<?php echo UPLOAD_URL . $this->gi->vessel_on_departure ?>"/>
                                </a>
                            </div>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <div style="clear: both;">&nbsp;</div>
            <?php $display = "style='display:none'" ?>
            <?php if ($this->gi->purpose_of_call == 'Loading' || $this->gi->purpose_of_call == 'Discharging'): ?>
                <?php $display = '' ?>
            <?php endif; ?>
            <span id="wrap-cargo-operations" <?php echo $display ?>>
                <h1 class="first"> Cargo operations</h1>
                <div class="cleft" style="width: 70%; border-right: none">
                    <div class="item">
                        <label for="net_weight">Commenced cargo ops:</label>
                        <div class="reselect">
                            <?php if ($this->gi->commenced_cargo): ?>
                                <?php echo $this->gi->commenced_cargo ? date(DATE_FORMAT, $this->gi->commenced_cargo) : "" ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="item">
                        <label for="gross_weight">Completed cargo ops:</label>
                        <div class="reselect">
                            <?php if ($this->gi->completed_cargo): ?>
                                <?php echo $this->gi->completed_cargo ? date(DATE_FORMAT, $this->gi->completed_cargo) : "" ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                    <span id='wrap_loaded_cargo' style='<?php echo $this->gi->purpose_of_call == 'Discharging' ? 'display:none' : '' ?>'>
                        <div class="item">
                            <label for="total_cargo_loaded_last_24h">Total cargo loaded last 24 hour:</label>
                            <div class="reselect">
                                <?php if ($this->gi->total_cargo_loaded_last_24h): ?>
                                    <?php echo Core_Util::formatNumber($this->gi->total_cargo_loaded_last_24h) . ' ' . $this->gi->tcll24h_unit ?> 
                                <?php else: ?>
                                    N/A
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="item">
                            <label for="total_cargo_loaded_uptodate">Total cargo loaded up to date:</label>
                            <div class="reselect">
                                <?php if ($this->gi->total_cargo_loaded_uptodate): ?>
                                    <?php echo Core_Util::formatNumber($this->gi->total_cargo_loaded_uptodate) . ' ' . $this->gi->tclutd_unit ?>
                                <?php else: ?>
                                    N/A
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="item">
                            <label for="balance_to_load">Balance to load:</label>
                            <div class="reselect">
                                <?php if ($this->gi->quantity && $this->gi->total_cargo_loaded_uptodate): ?>
                                    <?php echo Core_Util::formatNumber($this->gi->quantity - $this->gi->total_cargo_loaded_uptodate) ?> <?php echo $this->gi->tclutd_unit ?>
                                <?php else: ?>
                                    N/A
                                <?php endif; ?>
                            </div>
                        </div>
                    </span>
                    <span id='wrap_discharged_cargo' style='<?php echo $this->gi->purpose_of_call == 'Loading' ? 'display:none' : '' ?>'>
                        <div class="item">
                            <label for="total_cargo_discharged_last_24h">Total cargo discharged last 24 hour:</label>
                            <div class="reselect">
                                <?php if ($this->gi->total_cargo_discharged_last_24h): ?>
                                    <?php echo Core_Util::formatNumber($this->gi->total_cargo_discharged_last_24h) . ' ' . $this->gi->tcdl24h_unit ?>
                                <?php else: ?>
                                    N/A
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="item">
                            <label for="total_cargo_discharged_uptodate">Total cargo discharged up to date:</label>
                            <div class="reselect">
                                <?php if ($this->gi->total_cargo_discharged_uptodate): ?>
                                    <?php echo Core_Util::formatNumber($this->gi->total_cargo_discharged_uptodate) . ' ' . $this->gi->tcdutd_unit ?>
                                <?php else: ?>
                                    N/A
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="item">
                            <label for="balance_to_load">Balance to discharge:</label>
                            <div class="reselect">
                                <?php if ($this->gi->quantity && $this->gi->total_cargo_discharged_uptodate): ?>
                                    <?php echo Core_Util::formatNumber($this->gi->quantity - $this->gi->total_cargo_discharged_uptodate) ?> <?php echo $this->gi->tcdutd_unit ?>
                                <?php else: ?>
                                    N/A
                                <?php endif; ?>
                            </div>
                        </div>
                    </span>
                    <div class="item">
                        <label for="net_weight">Net weight:</label>
                        <div class="reselect">
                            <?php if ($this->gi->cargo_net_weight): ?>
                                <?php echo Core_Util::formatNumber($this->gi->cargo_net_weight) . ' ' . $this->gi->net_weight_unit ?> 
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>          
                    <div class="item">
                        <label for="gross_weight">Gross weight:</label>
                        <div class="reselect">
                            <?php if ($this->gi->cargo_gross_weight): ?>
                                <?php echo Core_Util::formatNumber($this->gi->cargo_gross_weight) . ' ' . $this->gi->gross_weight_unit ?>
                            <?php else: ?> 
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>  
                </div>
                <div style="clear: both;">&nbsp;</div>
            </span>
            <?php $display = "style='display:none'" ?>
            <?php if ($this->gi->purpose_of_call == 'Crew change'): ?>
                <?php $display = '' ?>
            <?php endif; ?>
            <span id="wrap-crew-service" <?php echo $display ?>>
                <h1 class="first"> Crew Service</h1>
                <div class="cleft" style="width: 70%; border-right: none">
                    <div class="item">
                        <label style="width: 19.5%;">On-signers status: </label>
                        <div class="reselect" style="float:left">
                            <?php if ($this->gi->on_signer_status): ?>
                                <?php echo $this->gi->on_signer_status ?> - 
                                <?php echo $this->gi->on_signer_status_date ? date(DATE_FORMAT, $this->gi->on_signer_status_date) : '' ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>  
                    <div class="item">
                        <label style="width: 19.5%;">Off-signers status: </label>
                        <div class="reselect" style="float:left">
                            <?php if ($this->gi->off_signer_status): ?>
                                <?php echo $this->gi->off_signer_status ?> - 
                                <?php echo $this->gi->off_signer_status_date ? date(DATE_FORMAT, $this->gi->off_signer_status_date) : '' ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>   
                </div>
                <div style="clear: both;">&nbsp;</div>
            </span>
            <?php $display = "style='display:none'" ?>
            <?php if ($this->gi->purpose_of_call == 'Dunnage'): ?>
                <?php $display = '' ?>
            <?php endif; ?>
            <span id="wrap-dunnage" <?php echo $display ?>>
                <h1 class="first"> Dunnage</h1>
                <div class="cleft" style="width: 70%; border-right: none">
                    <div class="item">
                        <label style="width: 28%;">Commenced dunnage</label>
                        <div class="reselect" style="float:left">
                            <?php if ($this->gi->commenced_dunnage): ?>
                                <?php echo date(DATE_FORMAT, $this->gi->commenced_dunnage) ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="item">
                        <label style="width: 28%;">Completed dunnage</label>
                        <div class="reselect" style="float:left">
                            <?php if ($this->gi->completed_dunnage): ?>
                                <?php echo date(DATE_FORMAT, $this->gi->completed_dunnage) ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <div style="clear: both;">&nbsp;</div>
            </span>
            <?php $display = "style='display:none'" ?>
            <?php if ($this->gi->purpose_of_call != 'Crew change'): ?>
                <?php $display = '' ?>
            <?php endif; ?>
            <span id="wrap-daily-photos" <?php echo $display ?>>
                <h3 class="table"> Daily photos</h3>
                <?php if ($this->folders): ?>
                    <?php foreach ($this->folders as $folder): ?>
                        <div class="folder file-new">
                            <a href='javascript:showPhotos("<?php echo $folder->id ?>")'><?php echo $folder['name'] ?></a>
                        </div>
                    <?php endforeach; ?>
                <?php endif; ?>
                <div style="clear: both;">&nbsp;</div>
            </span>
            <?php if ($this->gi->purpose_of_call == 'Crew change'): ?>
                <h3 class="first"> Crew documents</h3>
            <?php else: ?>
                <h3 class="first"> Cargo documents</h3>
            <?php endif; ?>
            <?php if ($this->doc_folders): ?>
                <?php foreach ($this->doc_folders as $folder): ?>
                    <div class="folder file-new">
                        <a href='javascript:showDocs("<?php echo $folder->id ?>")'><?php echo $folder['name'] ?></a>
                    </div>
                <?php endforeach; ?>
            <?php endif; ?>
            <div style="clear: both;">&nbsp;</div>
            <h1 class="first"> Remittances detail</h1>
            <table id="tbl_remittances" width="100%" border="0" cellpadding="0" cellspacing="0" class="row">
                <tr>
                    <th scope="col" class="number" width="5%">Remittance No.</th>
                    <th scope="col" class="type" width="15%">From</th>
                    <th scope="col" class="type" width="15%">Date</th>
                    <th scope="col" class="type" width="5%">Amount</th>
                    <th scope="col" class="type" width="15%">Remarks</th>
                </tr>
                <?php $index = 1 ?>
                <?php foreach ($this->remittances_detail as $rem): ?>
                    <tr>
                        <td class="rem_no">
                            <?php echo $index++; ?>
                        </td>
                        <td>
                            <?php echo $rem->fullname ?>
                        </td>
                        <td>
                            <?php echo date('d/m/Y', $rem->date) ?>
                        </td>
                        <td>
                            <?php echo Core_Util::displayCurrrency($rem->amount) ?>
                        </td>
                        <td>
                            <?php echo $rem->remarks ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
            <h1 class="first"> Services</h1>
            <form method="GET" id="frm_export_invoice" action="<?php echo $this->baseUrl() ?>/service/disbursement" target="_blank">
                <?php
                if (!empty($this->session->user) &&
                        ($this->session->user->role == Core_Role::ROLE_INPUT ||
                        $this->session->user->role == Core_Role::ROLE_ADMIN)):
                    ?>
                    <input type="submit" class="submit-button" value="Export"/>
                <?php endif; ?>
                <input type="hidden" value="<?php echo $this->gi->id ?>" name="giid"/>
                <table id="tbl_services" width="100%" border="0" cellpadding="0" cellspacing="0" class="row">
                    <tr>
                        <th scope="col" class="number" width="10%">Service No.</th>
                        <th scope="col" class="type" width="15%">Description of Port Expenses</th>
                        <th scope="col" class="type" width="5%">Invoice number</th>
                        <th scope="col" class="type" width="10%">Amount in USD</th>
                        <th scope="col" class="type" width="15%">Remarks</th>
                        <?php
                        if (!empty($this->session->user) &&
                                ($this->session->user->role == Core_Role::ROLE_INPUT ||
                                $this->session->user->role == Core_Role::ROLE_ADMIN)):
                            ?>
                            <th scope="col" class="type" width="5%">Invoice</th>
                        <?php endif; ?>
                    </tr>
                    <?php $index = 1; ?>
                    <?php $totalService = 0 ?>
                    <?php foreach ($this->services_detail as $service_detail): ?>
                        <tr>
                            <td class="service_no">
                                <?php echo $index++ ?>
                            </td>
                            <td style="text-align: left">
                                <?php echo $service_detail->name ?>
                            </td>
                            <td>
                                <?php echo $service_detail->voucher ?>
                            </td>
                            <td style="text-align: right; padding-right: 20px">
                                <?php echo Core_Util::displayCurrrency($service_detail->amount) ?>
                                <?php $totalService += $service_detail->amount ?>
                            </td>
                            <td style="text-align: left">
                                <?php echo $service_detail->remarks ?>
                            </td>
                            <?php
                            if (!empty($this->session->user) &&
                                    ($this->session->user->role == Core_Role::ROLE_INPUT ||
                                    $this->session->user->role == Core_Role::ROLE_ADMIN)):
                                ?>
                                <td>
                                    <input type="checkbox" value="<?php echo $service_detail->id ?>" name="sids[]"/>
                                </td>
                            <?php endif; ?>
                        </tr>
                    <?php endforeach; ?>
                    <tr>
                        <td colspan="3" style="text-align: right; font-weight: bold">
                            Total:
                        </td>
                        <td style="font-weight: bold;text-align: right; padding-right: 20px">
                            <?php echo Core_Util::displayCurrrency($totalService) ?>
                        </td>
                        <td></td>
                        <td></td>
                    </tr>
                </table>
            </form>
            <p style="margin-top: 10px; width: 100%">
                Say: US dollars <?php echo Core_Util::convert_number_to_words($totalService) ?>
            </p>
        </div>
    </div>
</div>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/fancybox/jquery.fancybox.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseUrl() ?>/public/js/fancybox/jquery.fancybox.css" />
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/jquery-migrate.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/jquery.boxy.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseUrl() ?>/public/css/boxy.css"/>
<script>
    $(window).load(function() {
        var left_height = $(".gi_left").height();
        var right_height = $(".gi_right").height();
        if (left_height < right_height) {
            $(".gi_left").height(right_height);
        }
        $(".fancybox").fancybox();
    });
    function showPhotos(folder_id)
    {
        Boxy.load('<?php echo $this->baseUrl() ?>/service/show-folder-photo/fid/' + folder_id, {modal: true});
    }
    function showDocs(folder_id)
    {
        Boxy.load('<?php echo $this->baseUrl() ?>/service/show-folder-doc/fid/' + folder_id, {modal: true});
    }
</script>